<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Aestate: aestate/util/others.py Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aestate
   &#160;<span id="projectnumber">1.0.5</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_374ee6e3281d8312d956f1f155302869.html">aestate</a></li><li class="navelem"><a class="el" href="dir_f4fb22c2f037e52003d190fd7f014e82.html">util</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">others.py</div>  </div>
</div><!--header-->
<div class="contents">
<a href="others_8py.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html">    1</a></span>&#160;<span class="comment"># -*- utf-8 -*-</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"># @Time: 2021/5/30 10:17</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"># @Author: CACode</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="keyword">import</span> os</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="keyword">import</span> time</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="keyword">from</span> datetime <span class="keyword">import</span> datetime</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="keyword">from</span> <a class="code" href="namespaceaestate_1_1conf.html">aestate.conf</a> <span class="keyword">import</span> BASE_ATTR</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160; </div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#ae478a3384f56aecc3c2216fc1e519723">   11</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#ae478a3384f56aecc3c2216fc1e519723">conversion_types</a>(val):</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="stringliteral">    将val的类型转换为字符串并插入array</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;    <span class="keywordflow">if</span> isinstance(val, datetime):</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;        val = val.strftime(<span class="stringliteral">&#39;%Y-%m-%d %H:%M:%S&#39;</span>)</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    <span class="keywordflow">return</span> val</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160; </div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#a3f0ad8048a78a5d5e58b8f8654cc8190">   20</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#a3f0ad8048a78a5d5e58b8f8654cc8190">date_format</a>(time_obj=time, fmt=&#39;%Y-%m-%d %H:%M:%S<span class="stringliteral">&#39;) -&gt; str:</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="stringliteral">    时间转字符串</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="stringliteral">    :param time_obj:</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="stringliteral">    :param fmt:</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="stringliteral">    :return:</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    _tm = time_obj.time()</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    _t = time.localtime(_tm)</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="keywordflow">return</span> time.strftime(fmt, _t)</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160; </div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#af0a75a1682ba5f0cf5f883b7523faa37">   32</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#af0a75a1682ba5f0cf5f883b7523faa37">time_to_datetime</a>(t_time):</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="stringliteral">    时间戳转datetime</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    <span class="keywordflow">try</span>:</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;        d_time = datetime.fromtimestamp(t_time)</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="keywordflow">except</span> OSError <span class="keyword">as</span> ose:</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;        <span class="keywordflow">return</span> <span class="keywordtype">None</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordflow">return</span> d_time</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160; </div>
<div class="line"><a name="l00043"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#a416be07c054ed693fd393131896ec1eb">   43</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#a416be07c054ed693fd393131896ec1eb">get_static_fields</a>(cls):</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="stringliteral">    获取类的非默认全局变量</span></div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    retD = list(set(dir(cls)).difference(set(BASE_ATTR)))</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    <span class="keywordflow">return</span> retD</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160; </div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#a24de34fe2f4a47b7293c2c3401398c4e">   51</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#a24de34fe2f4a47b7293c2c3401398c4e">fullname</a>(o):</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;获取对象的类名&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    module = o.__class__.__module__</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keywordflow">if</span> module <span class="keywordflow">is</span> <span class="keywordtype">None</span> <span class="keywordflow">or</span> module == str.__class__.__module__:</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        cls_name = o.__class__.__name__</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        cls_name = module + <span class="stringliteral">&#39;.&#39;</span> + o.__class__.__name__</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160; </div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="keywordflow">if</span> cls_name == <span class="stringliteral">&#39;type&#39;</span>:</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        cls_name = o.__base__.__module__ + <span class="stringliteral">&#39;.&#39;</span> + o.__base__.__name__</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <span class="keywordflow">return</span> cls_name</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160; </div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160; </div>
<div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#a3f6285307f75af293d8645cce37f1d5e">   65</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#a3f6285307f75af293d8645cce37f1d5e">logTupleToText</a>(next_line=True, *content):</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    temp = []</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <span class="keywordflow">if</span> isinstance(content, str):</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        temp.append(content)</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keywordflow">elif</span> isinstance(content, tuple):</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;        <span class="keywordflow">for</span> c <span class="keywordflow">in</span> content:</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;            <span class="keywordflow">if</span> isinstance(c, tuple):</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;                temp.extend(c)</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;            <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;                temp.append(str(c))</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        temp.append(str(content))</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="keywordflow">if</span> next_line:</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        temp.append(<span class="stringliteral">&#39;\n&#39;</span>)</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="keywordflow">return</span> <span class="stringliteral">&#39;&#39;</span>.join([str(_) <span class="keywordflow">for</span> _ <span class="keywordflow">in</span> temp])</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160; </div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1util_1_1others.html#a94720f3965606231d30e1a50b0b0112b">   82</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1util_1_1others.html#a94720f3965606231d30e1a50b0b0112b">write</a>(path, *content):</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;<span class="stringliteral">    写出文件</span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="stringliteral">    :param path:位置</span></div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;<span class="stringliteral">    :param content:内容</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="stringliteral">    :return:</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="comment"># 防止有些使用`/`有些用`\\`</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    _sep_path = []</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    s = path.split(<span class="stringliteral">&#39;/&#39;</span>)</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    [_sep_path.extend(item.split(<span class="stringliteral">&#39;\\&#39;</span>)) <span class="keywordflow">for</span> item <span class="keywordflow">in</span> s]</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    _path = <span class="stringliteral">&#39;&#39;</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    <span class="keywordflow">for</span> i <span class="keywordflow">in</span> _sep_path:</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        _end = _sep_path[len(_sep_path) - 1]</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="keywordflow">if</span> i != _end:</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;            _path += str(i) + os.sep</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;            _path += str(i)</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keywordflow">if</span> <span class="keywordflow">not</span> os.path.exists(_path):</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            <span class="keywordflow">if</span> <span class="stringliteral">&#39;.&#39;</span> <span class="keywordflow">not</span> <span class="keywordflow">in</span> i:</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;                os.makedirs(_path)</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    _write_content = <a class="code" href="namespaceaestate_1_1util_1_1others.html#a3f6285307f75af293d8645cce37f1d5e">logTupleToText</a>(<span class="keyword">True</span>, *content)</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <span class="keyword">with</span> open(os.path.join(_path), mode=<span class="stringliteral">&quot;a&quot;</span>, encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>) <span class="keyword">as</span> f:</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        f.write(_write_content)</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        f.close()</div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_af0a75a1682ba5f0cf5f883b7523faa37"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#af0a75a1682ba5f0cf5f883b7523faa37">aestate.util.others.time_to_datetime</a></div><div class="ttdeci">def time_to_datetime(t_time)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00032">others.py:32</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_a416be07c054ed693fd393131896ec1eb"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#a416be07c054ed693fd393131896ec1eb">aestate.util.others.get_static_fields</a></div><div class="ttdeci">def get_static_fields(cls)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00043">others.py:43</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_ae478a3384f56aecc3c2216fc1e519723"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#ae478a3384f56aecc3c2216fc1e519723">aestate.util.others.conversion_types</a></div><div class="ttdeci">def conversion_types(val)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00011">others.py:11</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1conf_html"><div class="ttname"><a href="namespaceaestate_1_1conf.html">aestate.conf</a></div><div class="ttdef"><b>Definition:</b> <a href="conf_8py_source.html#l00001">conf.py:1</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_a3f0ad8048a78a5d5e58b8f8654cc8190"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#a3f0ad8048a78a5d5e58b8f8654cc8190">aestate.util.others.date_format</a></div><div class="ttdeci">str date_format(time_obj=time, fmt='%Y-%m-%d %H:%M:%S')</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00020">others.py:20</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_a3f6285307f75af293d8645cce37f1d5e"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#a3f6285307f75af293d8645cce37f1d5e">aestate.util.others.logTupleToText</a></div><div class="ttdeci">def logTupleToText(next_line=True, *content)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00065">others.py:65</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_a24de34fe2f4a47b7293c2c3401398c4e"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#a24de34fe2f4a47b7293c2c3401398c4e">aestate.util.others.fullname</a></div><div class="ttdeci">def fullname(o)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00051">others.py:51</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1others_html_a94720f3965606231d30e1a50b0b0112b"><div class="ttname"><a href="namespaceaestate_1_1util_1_1others.html#a94720f3965606231d30e1a50b0b0112b">aestate.util.others.write</a></div><div class="ttdeci">def write(path, *content)</div><div class="ttdef"><b>Definition:</b> <a href="others_8py_source.html#l00082">others.py:82</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
